local YYDaBiao = require("activity.operate.DaBiao")
local ActDefine = require("activity.Define")
local PetLogic = require("pet.PetLogic")
local OperateActFL = require("activity.OperateActFL")
local LimitBuyExcel = require("excel.OperateActivity").limitBuy
local InnerDataManagerFL = require("innerdata.InnerDataManagerFL")
local InnerDataDefine = require("innerdata.Define")
local ObjHuman = require("core.ObjHuman")
local LvRank = require("activity.operate.LvRank")
local PataRank = require("activity.operate.PataRank")
local CopyFast = require("activity.operate.CopyFast")
local ActivityPlay = require("activity.operate.ActivityPlay")
local DailyGift = require("activity.operate.DailyGift")
local ChongzhiRebate = require("activity.operate.ChongzhiRebate")

function userLogin(human)
  YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_SHENBING)
  YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_HORSE)
  YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_EQUIPSTAGE)
  YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_EQUIPQUALITY)
  YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_EQUIPPOWER)
  CopyFast.checkCanGet(human)
  ActivityPlay.checkAllCanGet(human)
  ChongzhiRebate.checkCanGet(human)
end

function clearLimitBuyInfo(human, id)
  local activityNum = 999999
  local activity = LimitBuyExcel[activityNum]
  if not activity then
    return
  end
  for i=1, #activity.activityId do
    if activity.activityId[i] == id then
      human.db.YYLimitBuyTimes[20 + i-1] = 0
      break
    end
  end
end
function clearStatus(human, id)
  human.db.YYCopyFastIsGet = 0  
  for i=0, 7 do
    human.db.YYActivityPlayIsGet[i] = 0
  end
  human.db.YYPayDrawTimes = 0
  for i=ActDefine.OPERATEACT_TYPE_CHONGZHIREBATE, ActDefine.OPERATEACT_TYPE_CRITDRAW do
    if not OperateActFL.onCheckActIsRunning(i) or OperateActFL.onGetCurActVersion(i) ~= human.db.YYActivityId[i] then
      if ActDefine.OPERATEACT_TYPE_CHONGZHIREBATE == i then
        for i=0, 9 do
          human.db.YYChongzhiRebate[i] = 0
        end
      elseif ActDefine.OPERATEACT_TYPE_CHONGZHIDRAW == i then
        human.db.YYChongzhiDrawTimes = 0
      elseif ActDefine.OPERATEACT_TYPE_CHONGZHIRANK == i then
      elseif ActDefine.OPERATEACT_TYPE_LIMITBUY == i then
        for i=0,20 - 1 do 
          human.db.YYLimitBuyTimes[i] = 0
        end
      elseif i >= ActDefine.OPERATEACT_TYPE_SHENBING and i <= ActDefine.OPERATEACT_TYPE_EQUIPPOWER then
        for j=(i-5)*7, (i-5)*7 + 6 do
          human.db.YYDaBiaoStatus[j] = 0
        end
        clearLimitBuyInfo(human, i)
        if i == ActDefine.OPERATEACT_TYPE_PET then
          PetLogic.addAllRA(human)
        else
          YYDaBiao.checkCanGet(human, i)
        end
      elseif ActDefine.OPERATEACT_TYPE_QPOINT == i then
      elseif ActDefine.OPERATEACT_TYPE_CRITDRAW == i then
        human.db.YYCritDrawTimes = 0
      elseif ActDefine.OPERATEACT_TYPE_COPYFAST == i then
        
      elseif ActDefine.OPERATEACT_TYPE_ACTIVITYPLAY == i then
      elseif ActDefine.OPERATEACT_TYPE_PAYDRAW == i then
        human.db.YYPayDrawTimes = 0
      end
    end
  end
end

function sendYuanbao(human, oType, info)
  ObjHuman.addYuanbao(human, info.cnt, "yunyingAcvity")
end

function buyDailyGift(human, oType, info)
  DailyGift.sendDailyGift(human)
end

function onSbStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_SHENBING)
  end
end
function onPetStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    PetLogic.addAllRA(human)
  end
end
function onHorseStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_HORSE)
  end
end
function onBaowuStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_BAOWU)
  end
end
function onEquipStageStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_EQUIPSTAGE)
  end
end
function onEquipQuaStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_EQUIPQUALITY)
  end
end
function onEquipPowerStart(human)
  for __, human in pairs(ObjHuman.onlineHuman) do
    YYDaBiao.checkCanGet(human, ActDefine.OPERATEACT_TYPE_EQUIPPOWER)
  end
end
function setRankName(human, oType, info)
  if info.type == ActDefine.OPERATEACT_TYPE_LVRANK then
    LvRank.LV_RANK_NAME.name = info.name
    LvRank.LV_RANK_NAME.sex = info.sex
  else
    PataRank.PATA_RANK_NAME.name = info.name
    PataRank.PATA_RANK_NAME.sex = info.sex
  end
end

function clearRankName()
  LvRank.LV_RANK_NAME = {}
  PataRank.PATA_RANK_NAME = {}
end

InnerDataManagerFL.Register(InnerDataDefine.INNERDATA_TYPE_YUNYING_QPOINT, sendYuanbao)
InnerDataManagerFL.Register(InnerDataDefine.INNERDATA_TYPE_YUNYING_RANK, setRankName)
InnerDataManagerFL.Register(InnerDataDefine.INNERDATA_TYPE_DAILY_GIFT, buyDailyGift)
